package com.bdq.user.application.service;

import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.entity.common.PageResult;
import com.bdq.common.exception.ServerException;
import com.bdq.common.feign.content.ContentFeign;
import com.bdq.common.feign.content.param.UserPostPageParam;
import com.bdq.common.feign.content.vo.ContentListVO;
import com.bdq.common.feign.interaction.InteractionFeign;
import com.bdq.common.feign.interaction.param.UserInteractionPageParam;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author malei
 * @date 2024-05-15 18:29
 */
@Component
public class MyFeignClient {

    @Resource
    private ContentFeign contentFeign;

    @Resource
    private InteractionFeign interactionFeign;

    public PageResult<Long> pageUserPost(UserPostPageParam param){
        CommonResult<PageResult<Long>> result = contentFeign.pageUserPost(param);
        if (result.isError()) {
            throw new ServerException("[内容服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public List<ContentListVO> listContent(Long userId, List<Long> contentIds) {
        CommonResult<List<ContentListVO>> result = contentFeign.listContent(userId, contentIds);
        if (result.isError()) {
            throw new ServerException("[内容服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }

    public PageResult<Long> pageUserInteraction(UserInteractionPageParam param) {
        CommonResult<PageResult<Long>> result = interactionFeign.pageUserInteraction(param);
        if (result.isError()) {
            throw new ServerException("[交互服务异常]异常信息:".concat(result.getMsg()));
        }
        return result.getData();
    }
}
